package com.robot.backend.controller.robot;
import com.alibaba.fastjson2.JSONObject;
import com.robot.backend.pojo.Robot;
import com.robot.backend.service.robot.robotCRUDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/robotCRUD/")
public class robotCRUDController {
    @Autowired
        robotCRUDService robotCRUDService;
    @RequestMapping("add/")
    String addRobot(@RequestParam Map<String,String> map){
        System.out.println(map);
        return robotCRUDService.addRobot(map.get("title"),map.get("description"),map.get("content"),map.get("lang"));
    }
    @RequestMapping("update/")
    String updateRobot(@RequestParam Map<String,String> map){
        return robotCRUDService.updateRobot(Integer.parseInt(map.get("id")),map.get("title"),map.get("description"),map.get("content"),map.get("lang"));
    }
    @RequestMapping("delete/")
    String deleteRobot(@RequestParam Map<String,String> map){
        int id = Integer.parseInt(map.get("id"));
        return robotCRUDService.deleteRobot(id);
    }
    @RequestMapping("show/")
    JSONObject showRobot(@RequestParam Map<String,String> map){
        int page = Integer.parseInt(map.get("page"));
        int size = Integer.parseInt(map.get("size"));
        return robotCRUDService.showRobot(page,size);
    }
    @RequestMapping("allRobot/")
    List<Robot> allRobot(@RequestParam Map<String,String> map){
        return robotCRUDService.getAllRobot();
    }
}
